<?php
namespace app\admin\controller;

use think\Config;
use think\Controller;
use app\common\model\Admin as AdminModel;
use think\Session;
use utils\PwdUtil;
use app\common\model\ModuleSetting as ModuleSettingModel;
class AdminCommon extends Controller
{


    protected $beforeActionList = [
        'checkLogin'=>[
            'except'=>'login',
        ],
    ];

    /**
     * 登录校验
     * @desc 登录校验
     */
    protected function checkLogin(){
        $login_info = Session::get(Config::get('admin_token'));
        //判断是否登录
        if($login_info){
            $login_info = unserialize(PwdUtil::decode($login_info));
            if(isset($login_info['admin_name'])&&isset($login_info['pwd'])){
//                var_dump($login_info);die;

                if(AdminModel::get(['admin_name'=>$login_info['admin_name'],'pwd'=>$login_info['pwd']])){
                    $this->assign('setting',ModuleSettingModel::getSysSetting());
                    $this->assign('r_param',$this->request->param());
                    $this->assign('act',$this->request->module().DS.$this->request->controller().DS.$this->request->action());
                    $this->assign('admin_menu',AdminModel::getAdminMenu());
                    return;
                }
            }
        }
        if($this->request->isAjax()){
            $this->error('请登录','admin/index/login');
        }else{
            $this->redirect('admin/index/login');
        }

    }

}